import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
/**
 * 计算部门员工平均年龄
 */
public class Average {
    public static double average(List<Map<String, Object>> em) {
        BigDecimal sum = BigDecimal.ZERO;
        if (em.isEmpty()) {
            return 0.0;
        }
        for (Map<String, Object> aver : em) {
            BigDecimal decimal = new BigDecimal(aver.get("salary").toString());
            sum = sum.add(decimal);
        }
        //保留两位小数
        BigDecimal count = new BigDecimal(em.size());
        return sum.divide(count, 2, BigDecimal.ROUND_HALF_UP).doubleValue();
    }
}
